import http from "../utils/http.js";

/**
 * @description: 根据user对象进行登录
 * @return {*}
 * @param account
 * @param password
 */

//定义请求登录接口的方法
export async function loginApi(account, password) {
    return http.post('api/user/login', {}, {
        params: {
            userAccount: account,
            userPassword: password
        }
    });
}

/**
 * @description: 注册用户
 * @param account
 * @param password
 * @param checkPassword

 */
export async function registerApi(account, password, checkPassword) {
    return http.post('api/user/register', {}, {
        params: {
            userAccount: account,
            password: password,
            checkPassword: checkPassword
        }
    });
}


/**
 * @description: 用户退出登录
 * @return {Promise} 返回退出登录的结果
 * 成功: {code: 200, message: "账号已退出"}
 * 失败: {code: 401, message: "账号已退出"}
 */
export async function logoutApi() {
    try {
        return await http.post('/api/user/logout')
    } catch (error) {
        console.error('退出登录API请求失败:', error)
        throw error
    }
}



export async function updateInfoApi(user) { 
    return http.post('api/user/updateInfo', user);
}
